import React, { useSyncExternalStore } from 'react'
import store from './store'
import Child from './Child'

export default function UseSyncExternalStoreDemo() {
  const state = useSyncExternalStore(store.subscribe, () => {
    return store.getSnapshot()
  })

  return (
    <>
      <div>{state.data}</div>
      <button onClick={() => store.dispatch({type: 'add'})}>add</button>
      <Child></Child>
    </>
  )
}
